package timbap.visualizer.coreplugins.lib.artworkhue;

import java.util.ArrayList;
import java.util.List;

public class HueCluster implements Comparable<HueCluster> {

    List<Float> hueValues = new ArrayList<Float>();
    List<Float> hueFrequencies = new ArrayList<Float>();
    float summedUpHueFrequency = 0;

    public void addHueValue(float pHueValue, float pOccurrenceFreq) {
        hueValues.add(pHueValue);
        hueFrequencies.add(pOccurrenceFreq);
        summedUpHueFrequency += pOccurrenceFreq;
    }

    public float getSummedUpHueFrequency() {
        return summedUpHueFrequency;
    }

    public float getMedianHue() {
        if (hueValues.size() > 0) {
            int tMedianIndex = (int)hueValues.size() / 2;
            return hueValues.get(tMedianIndex);
        } else {
            return -1;
        }
    }

    public int compareTo(HueCluster o) {
        if (o != null) {
            return (int)Math.signum(summedUpHueFrequency - o.getSummedUpHueFrequency());
        } else {
            return 1;
        }
    }

    @Override
    public String toString() {
        return "frequency sum: \t" + summedUpHueFrequency
            + "\nhue values: \t" + hueValues.toString()
            + "\nhue freqs: \t" + hueFrequencies.toString();

    }

}
